package beans;

import java.util.List;

import dao.User;
import dao.UserDAO;

public class Userbean {

    /**
     * @param args
     */
    private UserDAO userDAO;
    private int pageSize;
    public Userbean() {
	userDAO = new UserDAO();
	pageSize = 6;
    }
    
    public int getPageCounts() {
        return pageSize;
    }

    public void setPageCounts(int pageSize) {
        this.pageSize = pageSize;
    }

    public User veryfyUser(String username, String password) {
	List<User> list = userDAO.findByUsername(username);
	if (list.size() > 0) {
	    User user1 = list.get(0);
	    if (password.equals(user1.getPassword())) {
		return user1;
	    } else {
		return null;
	    }
	} else {
	    return null;
	}
    }

    public boolean userExists(String username) {
	return userDAO.findByUsername(username).size() > 0 ? true : false;
    }

    public boolean modifyUser(User user) {
	return userDAO.update(user);
    }

    public boolean addUser(User user) {
	return userDAO.save(user);
    }

    public int getUserCounts(){
	return userDAO.getUserCounts();
    }
    
    public List<User> getAllUsers(int pageNum){
	return userDAO.findUsersByPage(pageNum, pageSize);
    }
    public boolean resetPassword(String userid){
	return userDAO.resetPassword(userid);
    }
    public static void main(String[] args) {
	// TODO Auto-generated method stub

    }

    
}
